package org.wjy.post.dao.impl;
import java.util.List;


import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.stereotype.Repository;
import org.wjy.post.dao.OrdersDao;
import org.wjy.post.util.BaseDao;
import org.wjy.post.vo.Orders;

/**     
 * 类名称：UserDaoImpl   
 * 类描述：用户控制dao实现数据库操作接口实现
 * 创建人：anan   
 * 创建时间：2012-12-21 下午11:07:43   
 * 修改人：anan  
 * 修改时间：2012-12-21 下午11:07:43   
 * 修改备注：   
 * @version        
 * */
@Repository("ordersDao")
public class OrdersDaoImpl extends BaseDao implements OrdersDao{

	@Override
	public List<Object[]> getorderslist() {
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
				Session session = getSession();
				Transaction tc = (Transaction) session.beginTransaction();
				String hql="select o.id as id,o.orderid as orderid,o.customerNo as " +
						"customerNo,u.customerName as customerName," +
						"o.goodsnum as customerName,o.payable as customerName,o.cre_time as cre_time," +
						"o.status as status from Orders as o,User as u where u.customerNo=o.customerNo";
				Query query=session.createQuery(hql);
				return query.list();
	}

	@Override
	public boolean addOrders(Orders order) {
		// TODO Auto-generated method stub
		Session session = getSession();
		Transaction tc = (Transaction) session.beginTransaction();
		session.save(order);
		try {
			tc.commit();
		} catch (Exception e) {
			e.printStackTrace();
		} 
		session.close();
		return true;
	}

	@Override
	public void update(Orders order) {
		// TODO Auto-generated method stub
		Session session = getSession();
		Transaction tc = (Transaction) session.beginTransaction();
		session.update(order);
		try {
			tc.commit();
		} catch (Exception e) {
			e.printStackTrace();
		} 
		session.close();
		
	}

	
	
}
